# Copyright (C) 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//tools/build:rules.bzl", "api_library", "apic_compile", "cc_copts")

api_library(
    name = "api",
    api = "encoder.api",
    apiname = "test",
    visibility = ["//visibility:public"],
)

apic_compile(
    name = "api_compiled",
    apis = [":api"],
    emit = [
        "encode",
        "context",
    ],
    module = "gapil_encoder_module",
    symbols = "c",
)

# Needed because apic_compile, can't (yet) return a cc provider.
# :api_compiled produces a .o file, so this doesn't actually compile anything.
cc_library(
    name = "api_lib",
    srcs = [":api_compiled"],
)

go_library(
    name = "go_default_library",
    srcs = [
        "cgo.go",
        "test.cpp",
        "test.h",
    ],
    cdeps = [
        ":api_lib",
        "//gapil/runtime/cc",
    ],
    cgo = True,
    cppopts = cc_copts(),
    importpath = "github.com/google/gapid/gapil/compiler/plugins/encoder/test",
    visibility = ["//visibility:public"],
    deps = [
        "//core/memory/arena:go_default_library",
        "//gapil/compiler/plugins/encoder/test/encoder_pb:go_default_library",
        "//gapis/memory/memory_pb:go_default_library",
        "@com_github_golang_protobuf//proto:go_default_library",
        "@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
    ],
)

go_test(
    name = "go_default_test",
    size = "small",
    srcs = ["encoder_test.go"],
    embed = [":go_default_library"],
    deps = [
        "//core/assert:go_default_library",
        "//core/data/protoutil:go_default_library",
        "//core/log:go_default_library",
        "//gapil/compiler/plugins/encoder/test/encoder_pb:go_default_library",
        "//gapis/memory/memory_pb:go_default_library",
        "@com_github_golang_protobuf//proto:go_default_library",
    ],
)
